package com.doudou.pay.helper.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.stereotype.Service;

import com.doudou.pay.helper.service.AuthTokenStrategyService;

@Service("authTokenStrategyService")
public class AuthTokenStrategyServiceImpl implements AuthTokenStrategyService {

	@Override
	public String selectAuthToken(Map<String, Integer> clientMap) {
		List<Map.Entry<String, Integer>> tokens = new ArrayList<>(clientMap.entrySet());
		
		//当存在多个
		if(tokens.size() > 1) {
			Collections.sort(tokens, new Comparator<Map.Entry<String, Integer>>() {

				@Override
				public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
					return o1.getValue().compareTo(o2.getValue());
				}
			});
		}
		
		return tokens.get(0).getKey();
	}
	
}
